#ifndef MYCLOCKDEMO_H
#define MYCLOCKDEMO_H

#include <QWidget>
#include <QMouseEvent>
#include <QMenu>
class MyClockDemo : public QWidget
{
    Q_OBJECT
public:
    explicit MyClockDemo(QWidget *parent = 0);

    void paintEvent(QPaintEvent *);

    void mousePressEvent(QMouseEvent* event){
        if(event->button()==Qt::LeftButton)
            mIsSelected=true;
        m_movePoint=event->pos();
    }

    void mouseMoveEvent(QMouseEvent* event){
        if(mIsSelected){
            QPoint movePos=event->globalPos();
            move(movePos-m_movePoint);
        }
    }

    void mouseReleaseEvent(QMouseEvent* event){
        mIsSelected=false;
    }
    void contextMenuEvent(QContextMenuEvent *event){
        //右键弹出
        QMenu *menu=new QMenu(this);
        menu->addAction("Close",this,SLOT(close()));
        menu->addAction("Move",this,SLOT(close()));
        QCursor cur=cursor();
        menu->exec(cur.pos());
    }

private:
    bool mIsSelected;
    QPoint m_movePoint;
};

#endif // MYCLOCKDEMO_H
